/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#include "ImageSimple.h"
#include <lib2d/hard/Renderer.h>
#include <lib2d/hard/Image.h>

namespace liba
{
namespace lib2d
{
namespace objects
{

hard::Image * ImageSimple::check_and_get_image( hard::Renderer * rend )
{
	hard::Image * img = get_rep()->get_image( rend );
	if( !img )
		return 0;
	if( !img->is_valid() )
	{
		get_rep()->start_loading();
		return 0;
	}

	return img;
}

void ImageSimple::blit( hard::Renderer * rend, const Vector2 & dst, const Rect & rect, int alpha )
{
	hard::Image * img = check_and_get_image( rend );
	if( !img )
		return;

	img->blit( dst, rect, alpha );
}

void ImageSimple::blit( hard::Renderer * rend, const Vector2 & dst, int alpha )
{
	hard::Image * img = check_and_get_image( rend );
	if( !img )
		return;

	img->blit( dst, alpha );
}

void ImageSimple::fill_rect( hard::Renderer * rend, const Rect & dst_rect, int alpha )
{
	hard::Image * img = check_and_get_image( rend );
	if( !img )
		return;

	img->fill_rect( dst_rect, alpha );
}

void ImageSimple::fill_rect( hard::Renderer * rend, const Rect & dst_rect, const Rect & src_rect, int alpha )
{
	hard::Image * img = check_and_get_image( rend );
	if( !img )
		return;

	img->fill_rect( dst_rect, src_rect, alpha );
}

} //namespace objects
} //namespace lib2d
} //namespace liba

